package xor.droid.nav;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.graphics.PixelFormat;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

public class CamControl extends Activity {

	//commit test 
	
	GLSurfaceView glView;
	CameraView cameraView;

	LayoutInflater controlInflater;

	String position;

	/** Called when the activity is first created. */
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		// Widescreen for AR Applications
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

		// Disable Title bar and the Notification Bar
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);

		// Create OpenGL Surface
		glView = new GLSurfaceView(this);

		// Choose Colors etc and set translucent to
		glView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
		// GLSurfaceView has to be Translucent or it will conceal the camerafeed
		glView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
		// The Renderer is implemented in another class
		glView.setRenderer(new GLRenderer());
		// Set as main view
		setContentView(glView);

		// Create CameraView
		cameraView = new CameraView(this);
		// Add it and use the whole Screen
		addContentView(cameraView, new LayoutParams(LayoutParams.WRAP_CONTENT,
				LayoutParams.WRAP_CONTENT));
		// Another view which contains the buttons and/or text
		controlInflater = LayoutInflater.from(getBaseContext());
		View viewControl = controlInflater.inflate(R.layout.control, null);

		this.addContentView(viewControl, new LayoutParams(
				LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
	}

	// TODO Obtain better OpenGL knowledge
	// Silly workaround to deal with Context loss in Android by always
	// finishing the app onPause(). Otherwise the OpenGL elements will not
	// be rerendered
	@Override
	protected void onResume() {
		super.onResume();
		glView.onResume();

		// // Workaround for the context lost issue
		glView.bringToFront();
		controlInflater = LayoutInflater.from(getBaseContext());
		View viewControl = controlInflater.inflate(R.layout.control, null);

		this.addContentView(viewControl, new LayoutParams(
				LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

	}

	@Override
	protected void onPause() {
		super.onPause();
		glView.onPause();
	}

}